%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calibration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear
clc

% Start from an initial guess for the parameters
load param
x_s=myx;

% Set lower and upper bounds for parameters search

lb = [0,0,-0.500000000000000,0.500000000000000,0,0,4,0,1,1,0,0,0,2,0.100000000000000,0.100000000000000,0.01,0.01]; 
ub = [11,1.20000000000000,0.500000000000000,1.80000000000000,1.20000000000000,1.20000000000000,20,6,5,5,1,1,1.20000000000000,7,5,5,25,25]; 

% Set optimization options
% Note: run with the parallel computing toolbox 

options = optimoptions('lsqnonlin','UseParallel',true, 'PlotFcn', 'optimplotresnorm', 'FiniteDifferenceStepSize', 1e-6, 'FunctionTolerance', 1e-6); % initial

% Run calibration
myx = lsqnonlin(@(x)err_obj_func_ls(x),x_s,lb,ub,options);

save calibrated_param myx 

